﻿(function () {
    if (!HTMLInputElement.prototype.setSelectionRange) {
        HTMLInputElement.prototype.setSelectionRange = function(start, end) {
            if (this.createTextRange) {
                var range = this.createTextRange();
                range.collapse(true);
                range.moveEnd('character', end);
                range.moveStart('character', start);
                range.select();
            }
        };
    }
})();

jQuery.fn.setSelection = function(start, end) {
    if (this.lengh == 0) return this;
    var input = this[0];
    //input.focus();
    input.setSelectionRange(start, end);
    return this;
};

jQuery.fn.carotToEnd = function () {
    var len = this.val().length;
    this.setSelection(len, len);
};
